home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10858 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  58 lines

  1. Path: oskar.Hagenuk.de!news
  2. From: berg@hagenuk.de (Jens Berg)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Another What does this do...
  5. Date: 20 Mar 1996 13:01:33 GMT
  6. Organization: Hagenuk Telecom GmbH
  7. Message-ID: <4iovjd$ime@oskar.Hagenuk.de>
  8. References: <4ijkrh$8t@apollo.isisnet.com>
  9. Reply-To: berg@hagenuk.de (Jens Berg)
  10. NNTP-Posting-Host: kst103_hat_jens_berg.hagenuk.de
  11. X-Newsreader: IBM NewsReader/2 v1.02
  12.  
  13. In <4ijkrh$8t@apollo.isisnet.com>, aa254@ccn.cs.dal.ca (Bill Fraser) writes:
  14. >Hi!  I've been trying mot of the weekend to make sense of Microsoft's
  15. >program to read Rich Text Formatted files.  I got it from their site
  16. >with the V1.4 rtf documentation and am hoping to adapt it to be able
  17. >to extract text and attributes for displaying word processor text on
  18. >character based color terminals ( color, bold, blink, inverse video ).
  19. >
  20. >Asside from never having programmed in C before, I figured I was doing
  21. >quite well until I came across the following statement:
  22. >
  23. >    pb = (char *)&dop;
  24. >
  25. >where pb and dop are defined as:
  26. >    char *pb;
  27. >and
  28. >    dop is structure DOP like this:
  29. >
  30. >    typedef struct doc_prop
  31. >    {
  32. >        int xaPage;
  33. >          ...
  34. >        char flandscape;
  35. >    } DOP;
  36. >
  37. As you said yourself, dop is a variable of structure DOP.
  38. &dop is the address of this var in memory or if you look at it the
  39. other way round it is a pointer to a location in memory, where a structure DOP
  40. is stored. Now this pointer is casted to a character pointer (that means, the compiler
  41. is forced to treat it as a charcter pointer) and assigned to the variable pb.
  42. You are now able to read the contents of your structure dop char by char, if you
  43. access *pb, *(pb+1), *(pb+2) etc. or (equivalent in this case) pb[0], pb[1], pb[2] etc.
  44.  
  45. To do something like this is extremly unportable code and should be avoided, as
  46. the chars you read are dependent on how your machine is designed (little/big endian,
  47. RISC/CISC architecture), how your compiler represents structures in memory, if it
  48. uses packed structures etc.
  49.  
  50. [Jens]
  51.  
  52. Jens Berg
  53. Hagenuk GmbH, Kiel - Germany
  54. Phone: +49 431 8818 70020, email: berg@hagenuk.de
  55. #include <standard.disclaimer>
  56. I only speak for myself!
  57.  
  58.